package com.sgzn.sgpay.web.controller;


import com.sgzn.sgpay.model.request.SgsLoginRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.result.LoginResult;
import com.sgzn.sgpay.service.SgsLoginService;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.LoginRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 用户登录控制器
 * @author huangsenguang
 */
@Slf4j
@Controller
@RequestMapping("/user")
public class UserLoginController {

    @Resource
    private SgsLoginService sgsLoginService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    @RequestMapping("/login")
    @ResponseBody
    public SgsResultResponse<LoginResult> login(LoginRequest request){
        return sgsLoginService.login(assembleRequest(request));
    }

    private SgsLoginRequest assembleRequest(LoginRequest request) {
        SgsLoginRequest sgsLoginRequest = new SgsLoginRequest();
        sgsLoginRequest.setTempCode(request.getCode());
        sgsLoginRequest.setLoginId("111");
        assembleCommonHandle.assemble(request, sgsLoginRequest);
        return sgsLoginRequest;
    }

}

